import { WebView } from '@tarojs/components';
import Taro, { useLoad, useShareTimeline } from '@tarojs/taro';
import { useRouter, useShareAppMessage } from '@tarojs/taro';
import { useEffect } from 'react';

function Webview() {
  const {params} = useRouter()
  let {title = '', url = ''} = params

  useLoad((option) => {
    url = option.url
  }) 

  const __title = decodeURIComponent(title)
  
  useShareAppMessage(() => {
    return {
      title: __title,
      path: `pages/webview/index?url=${url}`
    }
  })

  useShareTimeline(() => ({
    title: __title,
    path: `pages/webview/index?url=${url}`
  }))

  
  const __url = decodeURIComponent(url)

  useEffect(() => {
    Taro.setNavigationBarTitle({title: __title})
  }, [])

  return <WebView src={__url} />
}

export default Webview;